<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 字面量
        var person = {
            name: '小红',
            sex: '女',
            age: '3岁',
            refe: function () {
                console.log('我是' + this.name + ',' + '我今年' + this.age + '了');
            }
        }
        // person.refe();
        // 自定义构造函数
        function Person(name,sex,age) {
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.refe = function () {
                console.log('我是' + this.name + ',' + '我今年' + this.age + '了');
            }
        }
        var xiaoHong = new Person('小红','女','3岁');
        // xiaoHong.refe();
        // 工厂函数
        function Person(name,sex,age) {
            var obj = new Object();
            obj.name = name;
            obj.sex = sex;
            obj.age = age;
            obj.refe = function () {
                console.log('我是' + this.name + ',' + '我今年' + this.age + '了');
            }
            return obj;   
        }
        var xiaohong = Person('小红','女','3岁');
        // xiaohong.refe();
    </script>
</body>
</html>